/**
 * @author antonio081014
 * @since Jan 19, 2012, 6:25:15 PM
 */

public class GogoXCake {
    public String solve(String[] cake, String[] cutter) {
        for (int i = 0; i + cutter.length <= cake.length; i++) {
            for (int j = 0; j + cutter[0].length() <= cake[i].length(); j++) {
                if (checkCutter(cake, cutter, i, j)) {
                    for (int x = 0; x < cutter.length; x++) {
                        for (int y = 0; y < cutter[x].length(); y++) {
                            if (cutter[x].charAt(y) == '.')
                                cake[i + x] = cake[i + x].substring(0, y + j)
                                        + "X"
                                        + cake[i + x].substring(y + j + 1);
                        }
                    }
                }
            }
        }
        return checkCake(cake) ? "YES" : "NO";
    }

    public void print(String[] cake) {
        for (int i = 0; i < cake.length; i++)
            System.out.println(cake[i]);
    }

    public boolean checkCake(String[] cake) {
        for (int i = 0; i < cake.length; i++)
            for (int j = 0; j < cake[i].length(); j++)
                if (cake[i].charAt(j) == '.')
                    return false;
        return true;
    }

    public boolean checkCutter(String[] cake, String[] cutter, int x, int y) {
        for (int i = 0; i < cutter.length; i++) {
            for (int j = 0; j < cutter[i].length(); j++) {
                if (cutter[i].charAt(j) == '.')
                    if (cake[i + x].charAt(j + y) != cutter[i].charAt(j)) {
                        return false;
                    }
            }
        }
        return true;
    }

     public static void main(String[] args)
	{
		long time;
		String answer;
		boolean errors = false;
		String desiredAnswer;
		
		
		time = System.currentTimeMillis();
		answer = new GogoXCake().solve(new String[]{"X.X","...","...","X.X"}, new String[]{".X","..","X."});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "YES";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new GogoXCake().solve(new String[]{"..XX","...X","X...","XX.."}, new String[]{"..",".."});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "NO";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new GogoXCake().solve(new String[]{"...X..."}, new String[]{"..."});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "YES";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new GogoXCake().solve(new String[]{".X.","X.X",".X."}, new String[]{"."});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "YES";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new GogoXCake().solve(new String[]{"XXXXXXX","X.....X","X.....X","X.....X","XXXXXXX"}, new String[]{".X.","XXX",".X."});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "NO";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new GogoXCake().solve(new String[]{"..","X.",".X"}, new String[]{"..",".X","X."});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "NO";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new GogoXCake().solve(new String[]{"X..",".XX",".XX"}, new String[]{".XX",".XX","X.."});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = "NO";
		System.out.println("Your answer:");
		System.out.println("\t\"" + answer + "\"");
		System.out.println("Desired answer:");
		System.out.println("\t\"" + desiredAnswer + "\"");
		if (!answer.equals(desiredAnswer))
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		
		
		if (errors)
			System.out.println("Some of the test cases had errors :-(");
		else
			System.out.println("You're a stud (at least on the test data)! :-D ");
	}

}
// Powered by [KawigiEdit] 2.0!
